﻿{include file='pub/header'/}
<title>商品列表</title>
</head>
<body class="pos-r">
<div>
    <div class="page-container">
        <div class="text-c">
            商品名称：<input type="text" name="" id="" placeholder=" 商品名称" style="width:250px" class="input-text">
            商品货号：<input type="text" name="" id="" placeholder=" 商品货号" style="width:250px" class="input-text">
            <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜商品
            </button>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
                </a>
                <a class="btn btn-primary radius" onclick="asyncGoods()" href="javascript:;">
                    <i class="Hui-iconfont">&#xe641;</i> 同步商品库
                </a>
                <a class="btn btn-primary radius" onclick="product_add('添加商品','productAdd.html')" href="javascript:;">
                    <i class="Hui-iconfont">&#xe600;</i> 添加商品
                </a>
                <a class="btn btn-primary radius" onclick="updateImage()" href="javascript:;">
                    <i class="Hui-iconfont Hui-iconfont-huanyipi"></i> 更新商品图片
                </a>
            </span>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
               href="javascript:location.replace(location.href);" title="刷新">
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="40"><input name="" type="checkbox" value=""></th>
                    <th width="40">ID</th>
                    <th width="60">缩略图</th>
                    <th width="100">产品名称</th>
                    <th width="100">单价</th>
                    <th width="60">单位</th>
                    <th width="60">规格</th>
                    <th width="60">是否是组合商品</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $goodsList as $good}
                <tr class="text-c va-m">
                    <td><input name="id" type="checkbox" value="{$good.id}"></td>
                    <td>{$good.id}</td>
                    <td>
                        <a onClick="picture_show('查看图片', '{$good.img}')" data-src="" href="javascript:;">
                            <img width="60" class="product-thumb" src="{:explode(',', $good['img'])[0]}">
                        </a>
                    </td>
                    <td class="text-l">
                        {$good.name}
                    </td>
                    <td class="text-l">
                        {$good.cost}
                    </td>
                    <td class="text-l">
                        {$good.goodattr}
                    </td>
                    <td>
                        {$good.guige}
                    </td>
                    <td class="td-status">
                        {if condition="$good.combine_sta eq 1"}是
                        {else /}否
                        {/if}
                    </td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5"
                           onClick="product_edit('产品编辑','{:url(\'Product/productEdit\', [\'goodid\'=>$good.id])}')"
                           href="javascript:;" title="编辑">
                            <i class="Hui-iconfont">&#xe6df;</i>编辑
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$good.id}')"
                           href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;</i>删除
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
</div>

{include file='pub/footer'/}
<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[1, "asc"]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            {"orderable": false, "aTargets": [0, 8]}// 制定列不参与排序
        ]
    });

    //同步商品
    function asyncGoods() {
        layer.confirm("确定同步商品库？", function (index) {
            var li = layer.load();
            $.post("{:url('asyncGoods')}", null, function (res) {
                if (res.code == 1) {
                    layer.alert(res.msg, function () {
                        location.reload();
                    });
                } else {
                    layer.close(li);
                    layer.alert(res.msg);
                }
            });
        });
    }
    /**
     * 更新商品图片
     */
    function updateImage(){
        layer.load();
        $.post("{:url('updateImage')}", null, function (res) {
            layer.closeAll();
            if(res.code == 1){
                layer.alert('更新成功');
            }else{
                layer.alert(res.msg);
            }
        });
    }

    /*产品-添加*/
    function product_add(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*图片-查看*/
    function picture_show(title, url, id) {
        var imgsurl = url.split(',');
        var content = '';
        $.each(imgsurl, function (i, v) {
            content += "<img style='width: 120px;' src='" + v + "'/>";
        });
        var index = layer.open({
            type: 1,
            title: title,
            content: content
        });
        // layer.full(index);
    }

    /*产品-编辑*/
    function product_edit(title, url, id) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*产品-删除*/
    function product_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post("{:url('Product/delData')}", {idstr:id}, function (res) {
                if(res.code == 1){
                    layer.msg('删除成功');
                    $(obj).parents('tr').remove();
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    }
    //删除选中产品
    function datadel() {
        var $ids = $("input[name='id']:checked");
        if($ids.length<1){
            layer.alert('请选中后在操作');
            return false;
        }
        var idarr = new Array();
        $.each($ids, function (i, v) {
            idarr.push($(v).val());
        });
        var idStr = idarr.toString();
        layer.confirm('确认删除选中项？', function () {
            $.post("{:url('Product/delData')}", {idstr:idStr}, function (res) {
                if(res.code == 1){
                    layer.msg('删除成功');
                    $ids.parents('tr').remove();
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    }
</script>
</body>
</html>